import collections
class UndergroundSystem(object):

    def __init__(self):
        self.s_station = {}
        self.s_time = {}
        self.station = collections.defaultdict(int)
        self.station_count = collections.defaultdict(int)


    def checkIn(self, id, stationName, t):
        """
        :type id: int
        :type stationName: str
        :type t: int
        :rtype: None
        """
        self.s_station[id] = stationName
        self.s_time[id] = t


    def checkOut(self, id, stationName, t):
        """
        :type id: int
        :type stationName: str
        :type t: int
        :rtype: None
        """
        start = self.s_station.pop(id)
        start_time = self.s_time.pop(id)
        self.station[(start, stationName)] += t - start_time
        self.station_count[(start, stationName)] += 1

    def getAverageTime(self, startStation, endStation):
        """
        :type startStation: str
        :type endStation: str
        :rtype: float
        """
        return self.station[(startStation, endStation)] / self.station_count[(startStation, endStation)]
